package cn.cxy.calendarDemo

import android.Manifest
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.qw.soul.permission.SoulPermission
import com.qw.soul.permission.bean.Permission
import com.qw.soul.permission.bean.Permissions
import com.qw.soul.permission.callbcak.CheckRequestPermissionListener
import com.qw.soul.permission.callbcak.CheckRequestPermissionsListener
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        applyPermissions()
        addCalendarBtn.setOnClickListener {
            addCalendar()
        }
    }

    private fun addCalendar() {
        val startTime = System.currentTimeMillis() / 1000 + 120
        val endTime = startTime + 60 * 10
        SystemCalendarHandler.insertCalendarEventAndReminder(
            this, "测试日历",
            null, startTime, endTime, 0, CalendarConstantData.CALENDAR_EVENT_REPEAT_NEVER,
            "日历详细信息", null, 0
        )
    }

    private fun applyPermissions() {
        SoulPermission.getInstance()
            .checkAndRequestPermissions(
                Permissions.build(
                    Manifest.permission.READ_CALENDAR,
                    Manifest.permission.WRITE_CALENDAR
                ),
                object : CheckRequestPermissionsListener {
                    override fun onAllPermissionOk(allPermissions: Array<out Permission>?) {
                    }

                    override fun onPermissionDenied(refusedPermissions: Array<out Permission>?) {
                    }
                })
    }


}